package com.zhou.JavaAndroidFirm.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.zhou.JavaAndroidFirm.R;
import com.zhou.JavaAndroidFirm.activity.GuideActivity;
import com.zhou.JavaAndroidFirm.activity.MainActivity;

/**
 * @author Administrator
 * @date 2018/7/13 0013
 * @des
 */
public class GuigeAdapter extends PagerAdapter {
    private int[] guides;
    private Context mContext;

    public GuigeAdapter(Context mContext, int[] guides) {
        this.mContext = mContext;
        this.guides = guides;

    }

    @Override
    public int getCount() {
        return guides.length;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = View.inflate(mContext, R.layout.item_guide, null);
        ImageView iv_guide = (ImageView) view.findViewById(R.id.iv_guide);
        Button btn_guide = (Button) view.findViewById(R.id.btn_guide);
        if (position == 3) {
            btn_guide.setVisibility(View.VISIBLE);
        }
        btn_guide.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mContext.startActivity(new Intent(mContext, MainActivity.class));
                ((GuideActivity) mContext).finish();
            }
        });
        iv_guide.setBackgroundResource(guides[position]);
        container.addView(view, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return POSITION_NONE;
    }
}
